/**
 * 组件基类
 */
export class Component {
    constructor(props = {}) {
      this.props = props;
      this.state = {};
      this.element = null;
      this.theme = props.theme || {};
    }
  
    setState(newState) {
      this.state = {...this.state, ...newState};
      this.update();
    }
  
    update() {
      if (this.element && this.render) {
        const newElement = this.render();
        if (newElement && this.element.parentNode) {
          this.element.replaceWith(newElement);
          this.element = newElement;
        }
      }
    }
  
    setText(text) {
      if (this.element) {
        this.element.textContent = text;
      }
    }
  
    render() {
      throw new Error('render() 必须由子类实现');
    }
  }